package algorithms;

import java.util.Random;

public class ThreeSumToZero {

	public int bruteForce(int[] intArray) {

		int N = intArray.length;
		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {
				for (int k = j+1; k < N; k++) {
					if (intArray[i] + intArray[j] + intArray[k] == 0) {
						System.out.println(intArray[i] + "," + intArray[j] + "," + intArray[k]);
						count++;
					}
				}
			}
		}
		return count;
	}

	public static void main(String[] args) {

		int size = 20;
		int[] intArray = new int[size];

		Random generator = new Random();
		for (int i = 0; i < size; i++) {
			intArray[i] = generator.nextInt(10);
			System.out.print(intArray[i] + " ");
		}
		System.out.println();

		ThreeSumToZero object = new ThreeSumToZero();
		int result = object.bruteForce(intArray);
		System.out.println("Result ==> " + result);
	}
}
